package tests.flexunit.utils
{
	import flexunit.framework.AssertionFailedError;
	import flexunit.framework.TestCase;
	
	import funit.resources.AssertResources;
	
	import sv.reflection.errors.ReflectionError;
	import sv.utils.ClassUtil;
	
	import mx.core.Application;	

	public class GetClassByNameTests extends TestCase
	{
		
		
		public function GetClassByNameTests( methodName:String = null )
		{
			super(methodName);
		}
		
		
//------------------------------------------------------------------------------
		
		public function testGetClassByName() : void
		{
			assertStrictlyEquals( Application, ClassUtil.getClassByName("mx.core.Application") );
		}
		
//------------------------------------------------------------------------------
		
		public function testGetClassByQualifiedName() : void
		{
			assertStrictlyEquals( Application, ClassUtil.getClassByName("mx.core::Application") );
		}
		
//------------------------------------------------------------------------------
		
		public function testGetClassFailureOnSimpleName() : void
		{
			try
			{
				ClassUtil.getClassByName("Application");
			}
			catch ( e:ReflectionError )
			{
				return;
			}
			catch ( e:Error )
			{
				throw	new AssertionFailedError(
							AssertResources.getString("Errors.AssertFailedError.UnexpectedErrorType", ClassUtil.getQualifiedClassName(e))
						);
			}
			
			throw	new AssertionFailedError(
							AssertResources.getString("Errors.AssertFailedError.ErrorTypeExpected", ClassUtil.getQualifiedClassName(ReflectionError))
						);
		}
		
//------------------------------------------------------------------------------
		
		public function testGetClassFailureOnMalformedName() : void
		{
			try
			{
				ClassUtil.getClassByName("mx.core:Application");
			}
			catch ( e:ReflectionError )
			{
				return;
			}
			catch ( e:Error )
			{
				throw	new AssertionFailedError(
							AssertResources.getString("Errors.AssertFailedError.UnexpectedErrorType", ClassUtil.getQualifiedClassName(e))
						);
			}
			
			throw	new AssertionFailedError(
							AssertResources.getString("Errors.AssertFailedError.ErrorTypeExpected", ClassUtil.getQualifiedClassName(ReflectionError))
						);
		}
		
//------------------------------------------------------------------------------
		
		public function testGetClassFailureOnNull() : void
		{
			try
			{
				ClassUtil.getClassByName(null);
			}
			catch ( e:ArgumentError )
			{
				return;
			}
			catch ( e:Error )
			{
				throw	new AssertionFailedError(
							AssertResources.getString("Errors.AssertFailedError.UnexpectedErrorType", ClassUtil.getQualifiedClassName(e))
						);
			}
			
			throw	new AssertionFailedError(
							AssertResources.getString("Errors.AssertFailedError.ErrorTypeExpected", ClassUtil.getQualifiedClassName(ArgumentError))
						);
		}
		
//------------------------------------------------------------------------------
		
	}
	
}
